﻿using GEPL.InterfaceLibrary;
using GEPL.StandardModulesLibrary.ViewModels.Turtle;
using GEPL.StandardModulesLibrary.Views.Turtle;
using System;
using System.Runtime.Serialization;

namespace GEPL.StandardModulesLibrary.Elements.Turtle
{
    [Serializable]
    public class TurtleGoElement : IElement
    {
        private readonly TurtleGoViewModel viewModel;

        public TurtleGoElement()
        {
            viewModel = new TurtleGoViewModel();
        }

        public TurtleGoElement(SerializationInfo info, StreamingContext context)
        {
            viewModel = new TurtleGoViewModel()
            {
                Forward = info.GetBoolean(nameof(viewModel.Forward)),
                Backward = info.GetBoolean(nameof(viewModel.Backward)),
                Steps = info.GetInt32(nameof(viewModel.Steps))
            };
        }

        public ElementType ElementType
        {
            get { return ElementType.NormalStatement; }
        }

        public ProjectType ProjectType
        {
            get { return ProjectType.TurtleGraphics; }
        }

        public string ElementName
        {
            get { return Properties.Resources.Names_Go; }
        }

        public object Data
        {
            get { return viewModel; }
        }

        public Type UserControlType
        {
            get { return typeof(TurtleGoView); }
        }

        public string GetScript()
        {
            var command = viewModel.Forward ? "GoForward" : "GoBackward";
            return String.Format("Turtle.{0}({1})", command, viewModel.Steps);
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(nameof(viewModel.Forward), viewModel.Forward);
            info.AddValue(nameof(viewModel.Backward), viewModel.Backward);
            info.AddValue(nameof(viewModel.Steps), viewModel.Steps);
        }
    }
}